﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UQualityQuestionnaireView : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
              
            }
        }
        protected override string DWZRef
        {
            get { return "UQualityQuestionnaireList"; }
        }

        /// <summary>
        /// 需要修改的ID
        /// </summary>
        protected int UQQID
        {
            get
            {
                return GetRequestValue<int>("UQQID");
            }
        }

        private UQualityQuestionnaireInfo _obj;
        protected UQualityQuestionnaireInfo obj
        {
            get
            {
                if (_obj == null)
                    _obj = UQualityQuestionnaireController.GetByUQQID(UQQID);
                return _obj;
                //OMenuController.ge
            }
        }

        private List<UQualityListInfo> _listuq;
        protected List<UQualityListInfo> listUQ
        {
            get
            {
                if (_listuq == null)
                    _listuq = UQualityQuestionnaireController.UQualityList_GetByUQQID(UQQID);
                return _listuq;
                //OMenuController.ge
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region 获取调查表模板
        protected string GetUQuestionTemplete()
        {
            string TempHtml = "";
            //TempHtml = UQualityQuestionnaireController.DC.Get<string>(DataCacheKey.UQualityTempleteDCKey);
            //if (!TempHtml.IsEmptyOrNull())
            //    return TempHtml;
            TempHtml = "";
            //  string ItemTmpHtmlTitleTemp = "<b>({0}){1}</b>";
            string ItemTmpHtmlConTemp = "<table width=\"100%\">{0}</table> ";
            List<UQualityTempleteInfo> allQtemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(0, 1);
            string trhtml = "";
            int tdnum = 0;
            trhtml = "<tr>";
            foreach (UQualityTempleteInfo item in allQtemp)
            {
                List<UQualityTempleteInfo> AllitemTemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(item.UQTID, item.QTType);
                if ((tdnum % 3) == 0 && tdnum != 0)
                {
                    trhtml = trhtml + "</tr><tr>";
                }
                trhtml = trhtml + string.Format("<td><label>{0}</label>", item.QTTitle);
                foreach (UQualityTempleteInfo item2 in AllitemTemp)
                {
                    string checkedstr = listUQ.Find(e => e.UQTID == item2.UQTID) == null ? "" : "checked";

                    trhtml = trhtml + string.Format("<input type=\"checkbox\" name=\"UQTIDS\" value=\"{0}\" {2}/>{1}", item2.UQTID, item2.QTTitle, checkedstr);
                }
                trhtml = trhtml + "</td>";
                tdnum++;
            }
            trhtml = trhtml + "</tr>";

            ItemTmpHtmlConTemp = string.Format(ItemTmpHtmlConTemp, trhtml);
            TempHtml = ItemTmpHtmlConTemp;
            //UQualityQuestionnaireController.DC.Add(DataCacheKey.UQualityTempleteDCKey, TempHtml);
            return TempHtml;
        }

        protected string GetUQualityTemplete2()
        {
            string TempHtml = "";
            //TempHtml = UQualityQuestionnaireController.DC.Get<string>(DataCacheKey.UQualityTempleteDCKey2);
            //if (!TempHtml.IsEmptyOrNull())
            //    return TempHtml;
            TempHtml = "";
            string ItemTmpHtmlTitleTemp = "<b>{0}</b>";
            string ItemTmpHtmlConTemp = "<table >{0}</table>";
            List<UQualityTempleteInfo> allQtemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(0, 2);

            foreach (UQualityTempleteInfo item in allQtemp)
            {
                TempHtml = TempHtml + string.Format(ItemTmpHtmlTitleTemp, item.QTTitle);
                List<UQualityTempleteInfo> AllitemTemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(item.UQTID, item.QTType);
                string trhtml = "";
                int tdnum = 0;
                // item.RowTDNum = item.RowTDNum+1;
                trhtml = "<tr>";
                foreach (UQualityTempleteInfo item2 in AllitemTemp)
                {
                    if ((tdnum % item.RowTDNum) == 0 && tdnum != 0)
                    {
                        trhtml = trhtml + "</tr><tr>";
                    }
                    string checkedstr = listUQ.Find(e => e.UQTID == item2.UQTID) == null ? "" : "checked";
                    trhtml = trhtml + string.Format("<td><input type=\"checkbox\" name=\"UQTIDS\" value=\"{0}\" {2}>{1}</td>", item2.UQTID, item2.QTTitle, checkedstr);
                    tdnum++;
                }
                trhtml = trhtml + "</tr>";

                TempHtml = TempHtml + string.Format(ItemTmpHtmlConTemp, trhtml);

            }
           // UQualityQuestionnaireController.DC.Add(DataCacheKey.UQualityTempleteDCKey2, TempHtml);
            return TempHtml;
        }
        #endregion

    }
}